import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { queryAllClass } from '/@/api/demo/student';
import { h, ref, reactive } from 'vue';
const { createMessage } = useMessage();
import { useMessage } from '/@/hooks/web/useMessage';
import moment from 'moment';
import { format } from 'path';
import { string } from 'vue-types';

//定义表格的列
export const StudentTableColumns: BasicColumn[] = [
    {
        title: '学号',
        dataIndex: 'no',
        fixed: 'left', //表格列固定在左边
        width: 100,
    },
    {
        title: '姓名',
        dataIndex: 'name',
        fixed: 'left', //表格列固定在左边
        width: 100,
    },
    {
        title: '性别',
        dataIndex: 'sex',
        fixed: 'left', //表格列固定在左边
        width: 80,
        slots: { customRender: 'userFlag' },
    },
    {
        title: '手机号',
        dataIndex: 'phone',
        width: 150,
    },
    {
        title: '出生日期',
        dataIndex: 'birthday',
        width: 100,
        format: 'date|YYYY-MM-DD'

    },
    {
        title: '入学日期',
        dataIndex: 'inSchoolDay',
        width: 100,
        format: 'date|YYYY-MM-DD'

    },
    {
        title: '班级',
        dataIndex: 'classCode',
        width: 100,
        slots: { customRender: 'classFlag' },

    },
    {
        title: '家庭住址',
        dataIndex: 'homeAddress',
        width: 200,
    },
];

// //定义查询表单
export const StudentQueryForm: FormSchema[] = [
    {
        field: 'keywords',
        label: '关键字',
        component: 'Input',
        colProps: { span: 5 },
    },
    {
        field: 'classNo',
        label: '班级',
        colProps: { span: 5 },
        component: 'ApiSelect',
        componentProps: {
            api: queryAllClass, //数据接口
            resultField: string,
            params: { id: 1 },
            optionFilterProp: 'label',
            immediate: true, //是否立即请求接口，否则将在第一次点击时候触发请求
            treeDefaultExpandAll: true, //默认展开
            fieldNames: { label: 'name', value: 'no', children: 'children' },
            multiple: true,
        }
    }

    // {
    //     field: 'tm',
    //     label: '入学时间',
    //     component: 'DatePicker',
    // componentProps: {
    //     valueFormat: 'YYYY-MM-DD',
    //     format: 'YYYY-MM-DD',
    //     showTime: {
    //         format: 'YYYY-MM-DD',
    //     }

    // },
    // }
];
//学生信息包含：学号、姓名、性别（男、女）、出生日期、入学日期、所在班级、电话、家庭住址。
// 其中phone和homeAddress可为空

// export interface StudentInfo {
//     no: string,
//     name: string,
//     sex: true,
//     phone?: string,
//     birthday: string,
//     inSchoolDay: string,
//     classCode: string,
//     homeAddress?: string
// }
//定义新增/修改表单
export const studentFormSchema: FormSchema[] = [
    {
        field: 'no',
        label: '学号',
        component: 'Input',
        required: false,
        show: false,
    },
    {
        field: 'name',
        label: '姓名',
        component: 'Input',
        required: true,
    },
    {
        field: 'sex',
        label: '性别',
        component: 'Input',
        required: true,
    },
    {
        field: 'phone',
        label: '手机号',
        component: 'InputNumber',
        componentProps: {
            controls: false,
            style: {
                width: '100%',
            },
        },
        required: false,
    },
    {
        field: 'birthday',
        label: '出生日期',
        component: 'DatePicker',
        componentProps: {
            valueFormat: 'YYYY-MM-DD',
            format: 'YYYY-MM-DD',
            showTime: {
                format: 'YYYY-MM-DD',
            }

        },
        required: true,
    },
    {
        field: 'inSchoolDay',
        label: '入学日期',
        component: 'DatePicker',
        componentProps: {
            valueFormat: 'YYYY-MM-DD',
            format: 'YYYY-MM-DD',
            showTime: {
                format: 'YYYY-MM-DD',
            }

        },
        required: true,
    },
    {
        field: 'classCode',
        label: '班级编号',
        component: 'Select',
        componentProps: {},
        required: true,
    },
    {
        field: 'homeAddress',
        label: '家庭住址',
        component: 'Input',
        required: false,
    },
];

//定义表格的列
export const StudentScoreColumns: BasicColumn[] = [
    {
        title: '课程号',
        dataIndex: 'courseNo',
        fixed: 'left', //表格列固定在左边
        width: 80,
    },
    {
        title: '课程名',
        dataIndex: 'courseName',
        fixed: 'left', //表格列固定在左边
        width: 100,
    },
    {
        title: '成绩',
        dataIndex: 'score',
        fixed: 'left', //表格列固定在左边
        width: 80,
    },
];

// export function getBasicClass() {
//     queryAllClass().then((res) => {
//         console.log('res', res);
//         let classOptions = [];
//         for (let d of res) {
//             classOptions.push({ value: d.no, label: d.name });
//             return classOptions;
//         }
//     })
//         .catch((ex) => {
//             console.log('catch ', ex);
//             createMessage.error(ex.msg);
//         });
// }